<meta name="content-type" content="text/html; charset=UTF-8" />
<!-- #set(PaginatedList<Product> productList) -->
<!-- #set(List<User> responsibleList) -->
<!--
		#set(
		pager = productList.pager,
		totalPResults = pager.getCountOfTotalResults(),
		totalPPages = pager.getCountOfTotalPages() * 1,
		pageSize = pager.pageSize,
		pagePNo = pager.pageNo,
		prePPageNo = (pagePNo==1?1:pagePNo -1),
		nextPPageNo = (totalPPages==pagePNo?totalPPages:(pagePNo + 1)),
		m =0,
		n =0
		)
-->

<div>
	<input name="productMemberPageNo" type="hidden" value="${pagePNo}"> 
	<input name="productMemberPrePageNo" type="hidden" value="${prePPageNo}"> 
	<input name="productMemberNextPageNo" type="hidden" value="${nextPPageNo}">
	<input name="productMemberTotalPPages" type="hidden" value="${totalPPages}" >
</div>

<label for="txtProductName" class="col-sm-1 control-label label-pro-chose" style="text-align: right;padding: 0px;">名称</label>
<div class="col-sm-2">
	<input type="text" required class="form-control" name="productName" id="productName" value="" >
</div>
<label for="inputMemberLevel" class="col-sm-1 control-label label-pro-chose" style="text-align: right;padding: 0px;">类型</label>
<div class="col-sm-2">
	<select class="selectpicker show-menu-arrow" data-width="100%" name="productType" id="productType">
		<option value="">全部</option>
		<option value="101">按次卡</option>
		<option value="102">按金额</option>
		<option value="107">按时间</option>
		<option value="108">实时扣费</option>
	</select>
</div>

<div class="panel-btn-search">
	<button id="btn_search_pro" type="button" onclick="changePPage(1)" class="btn btn-default btn-ade-default" style="margin-top: 3px;margin-right: -38px;">查询</button>
</div>
<br>
<div class="panel-heading panel-result-title">
	<h3 class="panel-title">查询结果</h3>
</div>
<!--#if(productList)-->
<table id="product_all_table" class="table table-bordered table-hover table-condensed tb" style="text-align: center;">
	<tr>
		<td class="td_ck">&nbsp;</td>
		<td>产品名称</td>
		<td>产品类型</td>
		<td>产品价格(元)</td>
		<td>有效起始时间</td>
		<td>有效截止时间</td>
	</tr>
	<!--#for(Product pro : productList)-->
	<tr id="product_tr_${pro.productId}" style="cursor:pointer;">
		<td><input type="checkbox" id="chk_id" name="chk_proname_${pro.productId}" value="${pro.productId}"></td>
		<td>${pro.name}</td>
		<td>
			<!-- #if(pro.type == 101) -->
				次卡 
			<!-- #else(pro.type == 102) -->
				时间卡 
			<!-- #else(pro.type == 107) -->
				金额卡 
			<!-- #else(pro.type == 103) -->
				年卡 
			<!-- #else(pro.type ==104) -->
				 季卡 
			<!-- #else(pro.type == 105) -->
				月卡 
			<!-- #else(pro.type == 106) -->
				半月卡 
			<!-- #else -->
				普通消费 
			<!-- #end -->
		</td>
		<td id="tdp_${pro.productId}">${pro.price}</td>
		<td>${pro.beginTime.format("yyyy-MM-dd")}</td>
		<td>${pro.endTime.format("yyyy-MM-dd")}</td>
	</tr>
	<!--#end-->
</table>


<div class="div_page">
	<ul class="pagination">
		<li><a href="javascript:void(0)" onclick="changePPage(1)">首页</a></li>
		<!-- #if(pagePNo==1 || pagePNo == 0) -->
		<li class="disabled" id="prePage"><a href="javascript:void(0)">上一页</a></li>
		<!-- #else -->
		<li id="prePage"><a href="javascript:void(0)">上一页</a></li>
		<!-- #end -->
		<!-- #if(pagePNo==totalPPages) -->
		<li class="disabled" id="nextPage"><a href="javascript:void(0)">下一页</a></li>
		<!-- #else -->
		<li id="nextPage"><a href="javascript:void(0)">下一页</a></li>
		<!-- #end -->
		<li id="tailPage"><a href="javascript:void(0)">尾页</a></li>
		<li><a>第<input id="txtPPageNumber" value="${pagePNo}" onkeydown="this.value=this.value.replace(/\D/g,'')" onkeyup="changePPage(this.value)"
				onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text" />~&nbsp;共&nbsp;<span id="span_totalPages">${totalPPages}</span>&nbsp;页/<span id="span_totalResults">${totalPResults}</span>条
		</a></li>
	</ul>
</div>
<!-- #else -->
<div class="panel-body">没有符合条件的数据</div>
<!-- #end -->



<div class="panel panel-info">
	<div class="panel-heading panel-result-title">
		<h3 class="panel-title">购买支付</h3>
	</div>
	<div class="div_search_result clear">
		<label for="realCost" class="col-sm-1 control-label label-pro-chose" style="text-align: right;padding: 0px;">实收</label>
		<div class="col-sm-2">
			<input type="text" class="form-control panel-text-bg" style="width: 100px;" id="realCost" />
		</div>
		<label for="payType" class="col-sm-1 control-label label-pro-chose" style=" text-align: right; padding: 0px;" >支付方式</label>
		<div class="col-sm-1" style="padding-right : 0px;">
			<select id="payType" class="selectpicker" data-width="100%" name="payType">
				<option value="1">现金</option>
				<option value="2">刷卡</option>
				<option value="3">转账</option>
				<option value="4">支票</option>
			</select>
		</div>
		
		<div class="col-sm-1" style="margin-left:20px;width:360px;padding-right:0px;font-size:16px !important;font-weight:bold;height:40px;line-height:40px;">
			当前余额：<span id="spMemberRemaining" style="font-size:16px !important;font-weight:bold;"></span>元，仍需支付：<span id="stillNeedPay" style="font-size:16px !important;font-weight:bold;">0.0</span>元。
		</div>
		
		<div class="panel-btn-search">
			<button id="buyButton" onclick="showBuyProducts()" type="button" class="btn btn-default btn-ade-default" style="margin-top: 3px;margin-right: -38px;">购买</button>
		</div>
		
	</div>
</div>

<script type="text/javascript">
	function changePPage(value) {
		value = value * 1;
		var totalPages = '${totalPPages}';
		
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		
		$("#txtPPageNumber").val(value);
		goToPPage(value);
	}
	function goToPPage(pageNo) {
		searchProducts(pageNo);
	}
	function searchProducts(defaultPageNo){
		var productName  = $("#productName").val();
		var productType  = $("#productType").val();
		var productPrice = $("#productPrice").val();
		var pageNo = $("#txtPPageNumber").val();
		if(defaultPageNo<=0){
			pageNo = 1;
		}else{
			pageNo = defaultPageNo;
		}
		$("#hidPPageNo").val(pageNo);
		$.post(
			"yueyogaAdmin/findMemberInfoProductInpage.jhtml",
			{"pageNo": pageNo,"productName":productName, "productType":productType, "productPrice":productPrice},
			function(result) {
				var message = eval("(" + result + ")");
				$("tr[id^='product_tr_']").remove();
				if(message.success){
					var total_length = message.totalPages;
					for(var i = 0;i <message.items.length;i ++) {
						var appender = "<tr id='product_tr_" + message.items[i].productId + "'><td><input type='checkbox' onclick='priceClick(" + message.items[i].productId + ")' name='chk_proname_" + message.items[i].productId + "' value='" + message.items[i].productId + "'></td><td>" + message.items[i].name + "</td><td>" + getProType(message.items[i].type*1) + "</td><td id='tdp_" + message.items[i].productId + "'>" + message.items[i].price + "</td><td>" + message.items[i].beginTime + "</td><td>" + message.items[i].endTime + "</td></tr>";
						$("#product_all_table").append(appender);
					}
					$("#span_totalPages").text(total_length);
					$("#span_totalResults").text(message.totalResults);
					$("input[name='productMemberPageNo']").val(pageNo);
					$("input[name='productMemberPrePageNo']").val((pageNo==1?pageNo:(pageNo-1)));
					$("input[name='productMemberNextPageNo']").val((pageNo>=total_length?total_length:(pageNo+1)));
					$("input[name='productMemberTotalPPages']").val(total_length);
					if(pageNo==1){
						$("#prePage").addClass("disabled");
						$("#prePage a").attr("href","javascript:void(0)");
					}else{
						$("#prePage").removeClass("disabled");
					}
					if(pageNo==total_length){
						$("#nextPage").addClass("disabled");
						$("#nextPage a").attr("href","javascript:void(0)");
					}else{
						$("#nextPage").removeClass("disabled");
					}
				} else {
					alert(message.msg);
				}
			}
		);
	}
	
	function priceClick(productId) {
		var amount = $("#amounts").val() * 1;
		var id = productId;
		var but = $("input[name='chk_proname_" + id + "']");
		if (but.is(':checked')) {
			var td_price = $("#tdp_" + id).text() * 1;
			amount = amount + td_price;
		} else {
			var td_price = $("#tdp_" + id).text() * 1;
			amount = amount - td_price;
		}
		$("#amounts").val(amount);
	}
	
	$(document).ready(function() {
		
		$("#productType").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
		
		$("#payType").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
		
		//上一页
		$("#prePage").click(function() {
			var prePageNo = $("input[name='productMemberPrePageNo']").val();
			changePPage(prePageNo);
			if(prePageNo <= 1)
				$(this).attr("class", "disabled");
			else {
				$(this).removeClass("disabled");
				$("#nextPage").removeClass("disabled");
			}
		});
		
		//下一页
		$("#nextPage").click(function() {
			var nextPageNo = $("input[name='productMemberNextPageNo']").val();
			changePPage(nextPageNo);
			var totalPages = '${totalPPages}';
			if(nextPageNo >= totalPages)
				$(this).attr("class", "disabled");
			else {
				$(this).removeClass("disabled");
				$("#prePage").removeClass("disabled");
			}
		});
		
		//尾页
		$("#tailPage").click(function() {
			var totalPage = $("input[name='productMemberTotalPPages']").val();
			changePPage(totalPage);
		});
		
		//只能一个复选框选中
		$("#product_all_table tr").find("input[type='checkbox']").click(function(){
			 $("#product_all_table tr").find(":checkbox:checked").prop('checked',false);
			$(this).prop('checked',true);
		});
		
		$("#product_all_table tr").click(function(){
			var me = $(this);
			var ckx = me.find(":input[type=checkbox]");
			var checked = ckx.prop("checked");
			if(checked == false){
				 $("#product_all_table tr").find(":checkbox:checked").prop('checked',false);
				 var price = $(me.children().get(3)).text();
				 var dprice = parseFloat(price);
				 var remain = parseFloat($("#spMemberRemaining").text());
				 var total = dprice - remain;
				 $("#stillNeedPay").text(total);//仍需支付
				 $("#realCost").val(total);//实收
			}
			ckx.prop("checked",!checked);
		});
		
		
	});
	function clearNoNumOfAlert(obj){

	    //得到第一个字符是否为负号
	    var t = obj.value.charAt(0);  
	       //先把非数字的都替换掉，除了数字和.   
	       obj.value = obj.value.replace(/[^\d.]/g,"");   
	       //必须保证第一个为数字而不是.   
	       obj.value = obj.value.replace(/^\./g,"");   
	       //保证只有出现一个.而没有多个.   
	       obj.value = obj.value.replace(/\.{2,}/g,".");   
	       //保证.只出现一次，而不能出现两次以上   
	       obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	       //如果第一位是负号，则允许添加
	       if(t == '-'){
	         obj.value = '-'+obj.value;
	       }
	}
	function getProType(type){
		var val = '';
		if(type){
			switch(type){
			  case 101:
				val= '次卡';
				break;
			  case 102:
				val= '金额卡';
				break;
			  case 107:
				val= '时间卡';
				break;
			  case 108:
				val= '实时扣费';
				break;
			}
		}
		return val;
	}
</script>
